﻿@using GraduationProject.Model;
@{
    Layout = null;
    var Province = ViewData["Province"] as Province[];
    var Level = ViewData["Level"] as ScenicLevel[];
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>景点添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link href="~/Content/layui/css/layui.css" rel="stylesheet" />
    <link href="~/Content/css/public.css" rel="stylesheet" />
</head>
<body class="childrenBody">
    <form class="layui-form" style="width:80%;">
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">景点名称</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input userName" name="SortName" id="SortName" lay-verify="required" placeholder="请输入景点名称">
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">景点说明</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input userName" name="Instructions" id="Instructions" lay-verify="required" placeholder="请输入景点名称">
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">景区省份</label>
            <div class="layui-input-block">
                <select lay-verify="required" name="SortProvince" id="SortProvince" lay-filter="column">
                    @foreach (var item in Province)
                    {
                        <option value="@item.ProvinceID">@item.ProvincelName</option>
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">景区城市</label>
            <div class="layui-input-block">
                <select lay-verify="required" name="SortCity" id="SortCity">
                    @foreach (var item in Province[0].Cities)
                    {
                        <option value="@item.CityID">@item.CityName</option>
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">景区级别</label>
            <div class="layui-input-block">
                <select lay-verify="required" name="SortLeveID" id="SortLeveID">
                    @foreach (var item in Level)
                    {
                        <option value="@item.ScenicLevelID">@item.ScenicLevelName</option>
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">位置X地点</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input userName" name="PlaceX" id="PlaceX" lay-verify="required" placeholder="请输入景点名称">
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">位置Y地点</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input userName" name="PlaceY" id="PlaceY" lay-verify="required" placeholder="请输入景点名称">
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input userName" name="Remark" id="Remark" lay-verify="required" placeholder="请输入景点名称">
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">简介</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input userName" name="Introduction" id="Introduction" lay-verify="required" placeholder="请输入景点名称">
            </div>
        </div>
        <div class="layui-upload">
            <button type="button" class="layui-btn" id="test1">上传图片</button>
            <div class="layui-upload-list">
                <img class="layui-upload-img" id="demo1">
                <p id="demoText"></p>
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-xs12">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="addUser">立即添加</button>
                <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">取消</button>
            </div>
        </div>
    </form>
    <script src="~/Content/js/jquery.min.js"></script>
    <script src="~/Content/layui/layui.js"></script>
    <script src="~/Content/js/admin/Selecttool.js"></script>
    <script>
        layui.use(['form', 'layer', 'upload'], function () {
            var form = layui.form
            layer = parent.layer === undefined ? layui.layer : top.layer,
                $ = layui.jquery, upload = layui.upload;
            var path = "";
            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                , url: '/Admin/AdminSortList/AdminUploadImage'
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        return layer.msg('上传失败');
                    }
                    path = res.data.src;
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
            form.on("submit(addUser)", function (data) {
                //弹出loading
                var index = top.layer.msg('数据提交中，请稍候', { icon: 16, time: false, shade: 0.8 });
                var params = {
                    SortName: $("#SortName").val(),
                    Instructions: $("#Instructions").val(),
                    PlaceX: $("#PlaceX").val(),
                    PlaceY: $("#PlaceY").val(),
                    Remark: $("#Remark").val(),
                    Picture: path,
                    ProvinceID: $("#SortProvince option:selected").val(),
                    CityID: $("#SortCity option:selected").val(),
                    ScenicLevelID: $("#SortLeveID option:selected").val(),
                    ProvinceName: $("#SortProvince option:selected").text(),
                    CityName: $("#SortCity option:selected").text(),
                    ScenicLevelName: $("#SortLeveID option:selected").text()
                };
                $.ajax({
                    type: "post",
                    url: "/Admin/AdminSortList/AdminInsert",
                    data: params,
                    dataType: "json",
                    success: function (res) {
                        if (res.code == 0) {
                            layer.msg(res.msg, { icon: 1 });
                        }
                        else {
                            layer.msg(res.msg, { icon: 2 });
                        }
                    }
                });
                return false;
            })

        })

    </script>
</body>
</html>